
var a = document.querySelectorAll('nav>ul>li>a');
//   console.log(aBtn)
for(var i = 0; i < a.length; i++){
    a[i].index = i;
    a[i].onclick = function() {
        // alert(this.index);
        for(var j = 0; j < a.length; j++){
            a[j].className = '';    
        }
        a[this.index].className = 'active';
        
    }  
}
//轮播图 
        

  require(['./config'],() => {
    require(['swiper','template','header','footer','jquery'],(Swiper,template) => {
      class Index{
        constructor(){
            // this.init()
            this.getBannerData()
        }
        init(){
            // 在这儿初始化 swiper
            var swiper = new Swiper('.swiper-container', {
              spaceBetween: 30,
              loop: true, 
              centeredSlides: true,
              autoplay: {
                delay: 2500,
                disableOnInteraction: false,
              },
              pagination: {
                el: '.swiper-pagination',
                clickable: true,
              },
              navigation: {
                nextEl: '.swiper-button-next',
                prevEl: '.swiper-button-prev',
              },
            })
        }
        // 这个方法是用来获取轮播图的数据
        getBannerData(){
            // console.log($)
            // 发送请求
            $.ajax({
                url:'/lib/indexBannerMock.json',
                dataType:'json'
            })
            .then(res => {
                // console.log(res)
                // 拿到数据渲染首页轮播图
                if(res.code === 200){
                    const list = res.result_body
                    // console.log(list)
                    const html1 = template('indexBannerTemplate',{list})
                    // console.log(html1)
                    $('.banner_swiperWrapper').html(html1)
                    // 应该再页面 html 标签已经加载完毕以后再去写 js 代码
                    this.init()
                }
            })
        }
    }
    return new Index()
    })
})